package zhongbo.java.air.dictionary.web.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.dictionary.model.AirAirport;
import zhongbo.java.air.dictionary.model.AirAlertZone;
import zhongbo.java.air.dictionary.service.IAirAirportService;

import javax.validation.Valid;

@RestController
@RequestMapping("/airPort")
@Api(tags = "机场接口")
public class AirAirportController {

    @Autowired
    private IAirAirportService<AirAirport> airAirportService;

//    @GetMapping("/queryByPage")
    @GetMapping("findPage")
    @ApiOperation("分页查询")
    public ResultVo<PageVo<AirAirport>> queryByPage(Integer page, Integer pageSize
            , String keyword, String fields
            , String oderByField, Boolean orderByAsc) {
        PageVo<AirAirport> airAirportPageVo = airAirportService.queryByPage(page, pageSize, keyword, fields, oderByField, orderByAsc);
        return ResultVo.ok(airAirportPageVo);
    }

//    @GetMapping("/selectById/{id}")
    @GetMapping("findOne")
    @ApiOperation("根据id查询机场信息")
    public ResultVo<AirAirport> queryById(String entityId) {
        AirAirport airAirport = airAirportService.queryById(entityId);
        return ResultVo.ok(airAirport);
    }

    @PostMapping("/add")
    @ApiOperation("添加机场信息")
    public ResultVo<AirAirport> add(@RequestBody @Valid AirAirport airAirport) {
        AirAirport insert = airAirportService.insert(airAirport);
        return ResultVo.ok(insert);
    }

//    @PutMapping("/edit")
    @PostMapping("/edit")
    @ApiOperation("修改机场信息")
    public ResultVo<AirAirport> edit(@RequestBody @Valid AirAirport airAirport) {
        AirAirport update = airAirportService.update(airAirport);
        return ResultVo.ok(update);
    }


//    @DeleteMapping("/deleteById/{id}")
    @GetMapping("delete")
    @ApiOperation("根据id删除机场信息")
    public ResultVo<String> deleteById(String entityId) {
        airAirportService.deleteById(entityId);
        return ResultVo.ok("删除成功");
    }

}
